﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ryscanner
{
    public class BaseAddress {
        public long basePtr;
        public long ptr;
        public long offset;
        public bool baseAddr;
    }
    public class SearchAddressNumValue
    {
        private long ptr;

        private byte[] value;

        private bool changed;

        private byte[] old;

        private bool baseAddr;

        public SearchAddressNumValue(long ptr, byte[] value, bool isBaseAddr) {
            this.ptr = ptr;
            this.value = value;
            this.baseAddr = isBaseAddr;
        }

        public SearchAddressNumValue(long ptr, byte[] value) {
            this.ptr = ptr;
            this.value = value;
        }
        static bool ByteArrayCompare(byte[] b1, byte[] b2)
        {
            return b1.SequenceEqual(b2);
        }
        public void UpdateVal(byte[] bytes) {

            if (!ByteArrayCompare(bytes, this.value)) {
                this.value = bytes;
                this.changed = true;
            }
        }

        public bool isChanged() {

            return this.changed;
        }

        public long getLongAddr() {
            return this.ptr;
        }

        public bool isBaseAddr() {
            return this.baseAddr;
        }
        public String getAddress() {
            string hexValue = this.ptr.ToString("X8");
            return hexValue;
        }
        public String getHexVal() {
            long v = this.getValue();
            string hexValue = v.ToString("X8");
            return hexValue;
        }
        public long getValue() {
            if (this.value.Length == 2) {
                return (long)BitConverter.ToInt16(this.value);
            }
            return (long)BitConverter.ToInt32(this.value);
        }
        public String getStr() {
            try {
                return Encoding.GetEncoding("gb2312").GetString(this.value);
            }
            catch (Exception) {
                return "";
            }
        }
    }
}
